package com.babble.manage.service;

import com.babble.manage.entity.OssFile;
import com.babble.manage.service.impl.ResourceServiceImpl;
import org.springblade.common.entity.MinioPolicy;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 远程调用资源
 *
 * @author wm
 */
@FeignClient(
	name = AppConstant.APPLICATION_RESOURCE_NAME,
	fallback = ResourceServiceImpl.class
)
public interface ResourceService {
	String API_PREFIX = "/oss/endpoint/";

	/**
	 * 通过文件流上传图片
	 *
	 * @param file
	 * @return
	 */
	@PostMapping(value = API_PREFIX + "upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	R<OssFile> upload(MultipartFile file);

	/**
	 * 获取策略，通过策略直传图片
	 *
	 * @param fileName    文件名
	 * @param contentType 文件类型
	 * @return
	 */
	@GetMapping(API_PREFIX + "policy")
	R<MinioPolicy> getPolicy(@RequestParam String fileName, @RequestParam String contentType);

	/**
	 * 删除图片
	 *
	 * @param filePath 文件路径
	 * @return
	 */
	@DeleteMapping(API_PREFIX + "delete")
	R delete(@RequestParam String filePath);

	/**
	 * 根据url批量删除图片
	 *
	 * @param filePaths 图片路径数组
	 * @return
	 */
	@DeleteMapping(API_PREFIX + "deletes")
	R deletes(@RequestBody List<String> filePaths);
}
